<?php

namespace Admin\Models\school;

use Admin\Models\BaseModel;
class XhschoolClassteacher extends BaseModel
{

    /**
     *
     * @var integer
     */
    public $iSCTId;

    /**
     *
     * @var integer
     */
    public $iSOCId;

    /**
     *
     * @var string
     */
    public $iTchId;

    /**
     *
     * @var string
     */
    public $sLogonName;

    /**
     *
     * @var string
     */
    public $sUserName;

    /**
     *
     * @var integer
     */
    public $iOp;

    /**
     *
     * @var integer
     */
    public $bIsMain;

    /**
     *
     * @var integer
     */
    public $bDelete;

    /**
     *
     * @var string
     */
    public $tCreateDate;

    /**
     *
     * @var string
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     */
    public $tLastModifyDate;

    /**
     *
     * @var string
     */
    public $iLastModifyUserId;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
        $this->setSource("XHSchool_ClassTeacher");
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHSchool_ClassTeacher';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhschoolClassteacher[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhschoolClassteacher
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 根据开班ID删除相关教师信息
     *
     * @param $openClassId
     * @return mixed
     *
     * create by ck 20160929
     */
    public static function deleteRecordByOpenClassId($openClassId)
    {
        return self::find([
            'conditions'    => 'iSOCId = :openClassId:',
            'bind'          => ['openClassId' => $openClassId]
        ])->delete();
    }

    /**
     * 创建记录
     *
     * @param $tchId                    --教师ID
     * @param $openClassId              --开班ID
     * @param int $op                   --操作码
     * @return XhschoolClassteacher
     *
     * create by ck 20160816
     * modify by ck 20160929
     */
    public static function createRecord($tchId, $openClassId, $op = 0)
    {
        $obj = new self;
        $obj->iSOCId    = $openClassId;
        $obj->iOp       = $op;
        $obj->iTchId    = $tchId;
        return $obj;
    }

    /**
     * 根据开班ID获取信息
     *
     * @param $openClassId
     * @return XhschoolClassteacher[]
     *
     * create by ck 20160816
     */
    public static function findByOpenClassId($openClassId)
    {
        return self::find(array(
            'conditions'    => 'iSOCId = :iOpenClassId: AND bDelete = 0',
            'bind'          => array(
                'iOpenClassId'  => $openClassId
            )
        ));
    }

}
